<?php
/**
* @copyright Amasty.
*/ 
class Verz_Home_Helper_Data extends Mage_Core_Helper_Abstract
{
    /**
     * @desc: find format date from $code of language
     * @author: nhut.nguyen
     */
    public function formatDate($code,$string_date){
        if($code=="en"){
            $string_date = date("m/d/Y",  strtotime($string_date));
        }
        else{
            $string_date = date("m/d/Y",  strtotime($string_date));
        }
        return $string_date;

    }
    public function formatToMySqlDate($code,$string_date,$splash="/"){
        /*
        if($code!="en"){

            $pieces = explode($splash, $string_date);
            $string_date = $pieces[1] . $splash . $pieces[0] .$splash. $pieces[2];

        }*/
        return $string_date;
    }
    /**
     * @desc just check mm/dd/yyyy
     * @author: nhut.nguyen
     */
    public function isDate($date){

        if(date("m/d/Y",strtotime($date))==CAN_NO_TIME){
            if($date==CAN_NO_TIME){
               return true;
            }
            return false;
        }
        else{
            return true;
        }
        return false;
    }
    public function getBabyMaxSize($width,$height,$nlWidth=MAX_WIDTH_IMAGE_BABY,$nlHeight=MAX_HEIGHT_IMAGE_BABY){

        $nWidth = $width;
        $nHeight= $height;
        if($width > $nlWidth){
            $nWidth = $nlWidth;
            $nHeight = ($nlWidth * $height)/$width;
            if($nHeight > MAX_HEIGHT_IMAGE_BABY ){
                $nHeight = MAX_HEIGHT_IMAGE_BABY;
                $nWidth = ($nHeight * $width)/$height;
                return array($nWidth,$nHeight);
            }
            return array($nWidth,$nHeight);
        }
        elseif($nHeight > $nlHeight) {
            $nHeight = $nlHeight;
            $nWidth = ($nHeight * $width)/$height;
            return array($nWidth,$nHeight);
        }
        return array($width,$height);
    }
    /**
	 * Check is ajax request
	 */
	public static function isAjax() {
		if (! empty ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) && strtolower ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest') {
			return true;
		}
		return false;
	}
    
    public static function resizeToWidth($width, $height, $reWidth) {
        return $reHeight = ($reWidth * $height) / $width;
    }
}